package com.kamistoat.meimeistore.member.service.impl;

import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kamistoat.common.utils.PageUtils;
import com.kamistoat.common.utils.Query;

import com.kamistoat.meimeistore.member.dao.MemberReceiveAddressDao;
import com.kamistoat.meimeistore.member.entity.MemberReceiveAddressEntity;
import com.kamistoat.meimeistore.member.service.MemberReceiveAddressService;


@Service("memberReceiveAddressService")
public class MemberReceiveAddressServiceImpl extends ServiceImpl<MemberReceiveAddressDao, MemberReceiveAddressEntity> implements MemberReceiveAddressService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<MemberReceiveAddressEntity> page = this.page(
                new Query<MemberReceiveAddressEntity>().getPage(params),
                new QueryWrapper<MemberReceiveAddressEntity>()
        );

        return new PageUtils(page);
    }

    /**
     * 计算运费
     *
     * @param attrId
     * @return
     */
    @Override
    public BigDecimal getFare(Long attrId) {
        MemberReceiveAddressEntity addressEntity = this.getById(attrId);
        // TODO 直接使用物流公司的第三方接口即可。这里用手机号后一位做运费
        String fare = addressEntity.getPhone().substring(addressEntity.getPhone().length() - 1);
        return new BigDecimal(fare);
    }

}